import axios from 'axios';
import { UserState } from '@/store/modules/user/types';

export interface UserParams {
  userId: number;
  username: string;
  nickName: string;
  email: string;
  phone: string;
  registrationDate: string;
}

export interface addUserParams {
  username?: string;
  nickName?: string;
  newPassword?: string;
  phone?: string;
  email?: string;
  roleIds?: number[];
}

export interface editUserParams {
  userId?: number | string;
  username?: string;
  nickName?: string;
  newPassword?: string;
  phone?: string;
  email?: string;
  roleIds?: number[];
}

export interface editUserInfoParams {
  /**
   * 手机号
   */
  phone: any;
  /**
   * 用户id
   */
  userId: any;
}

export interface EditPwdParams {
  oldPassword?: string;
  newPassword?: string;
}

/**
 * 获取登陆用户信息
 */
export function getUserInfo() {
  return axios.get<UserState>('/info');
}

export function userList(paramsData: UserParams) {
  return axios.get('/user/list', {params: paramsData});
}

// 根据用户id查询用户
export function userInfo(userId: number) {
  return axios.get(`/user/query/${userId}`);
}

// 新增用户
export function addUser(dataParams: addUserParams) {
  return axios.post('/user/add', dataParams);
}

// 修改用户信息
export function editUser(dataParams: editUserParams) {
  return axios.put('/user/edit', dataParams);
}

// 批量删除用户
export function removeBatch(userIds: number[]) {
  const param = {
    userIds: userIds
  }
  return axios.delete(`/user/remove`, {params: param});
}

// 修改用户信息
export function editInfo(data: editUserInfoParams) {
  return axios.put('/user/editIndividualInfo', data);
}

// 上传头像
export function uploadAvatar(data: any) {
  return axios.post('/user/avatar', data, {headers: {'Content-type': 'multipart/form-data'}});
}

// 修改密码
export function editPwd(dataParams: EditPwdParams) {
  return axios.put('/user/editPassword', dataParams);
}

// 修改状态
export function updateStatue(userId: number) {
  return axios.put('/user/updateStatus', {}, {params: {userId: userId}});
}

